#include "modbuswig.h"
#include "ui_modbuswig.h"
#include<QIcon>
//stm32硬件控制
ModbusWig::ModbusWig(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ModbusWig)
{
    ui->setupUi(this);
    fan_i=0;
    buzzer_i=0;
    led1_i=0;
    led2_i=0;
    led3_i=0;
    led4_i=0;
}

ModbusWig::~ModbusWig()
{
    delete ui;
}


void ModbusWig::on_fan_Button_clicked()   //风扇按钮
{
    QIcon icon1;
    if(fan_i==0)//关
    {
        icon1.addFile(":/images/open_fan.png");
        ui->fan_Button->setMinimumSize(100,150);
        ui->fan_Button->setMaximumSize(300,150);
        ui->fan_Button->setIcon(icon1);
        ui->fan_Button->setIconSize(QSize(50,50));
        fan_i=1;
        QString text="open_fan";
        emit close_open_Signal(text);//发送关闭风扇信号，主页面收到信号后把数据传回stm32
    }
    else
    {
        icon1.addFile(":/images/close_fan.png");
        ui->fan_Button->setMinimumSize(100,150);
        ui->fan_Button->setMaximumSize(300,150);
        ui->fan_Button->setIcon(icon1);
        ui->fan_Button->setIconSize(QSize(50,50));
        fan_i=0;
        QString text="close_fan";
        emit close_open_Signal(text);//当下位机收到close_fan时的数据，则关闭风扇
    }

}

void ModbusWig::on_buzzer_Button_clicked()     //蜂鸣器
{
    QIcon icon1;
    if(buzzer_i==0)//关
    {

        icon1.addFile(":/images/open_buzzer.png");
        ui->buzzer_Button->setMinimumSize(100,150);
        ui->buzzer_Button->setMaximumSize(300,150);
        ui->buzzer_Button->setIcon(icon1);
        ui->buzzer_Button->setIconSize(QSize(50,50));
        buzzer_i=1;
        QString text="open_buzzer";
        emit close_open_Signal(text);
    }
    else
    {
        icon1.addFile(":/images/close_buzzer.png");
        ui->buzzer_Button->setMinimumSize(100,150);
        ui->buzzer_Button->setMaximumSize(300,150);
        ui->buzzer_Button->setIcon(icon1);
        ui->buzzer_Button->setIconSize(QSize(50,50));
        buzzer_i=0;
        QString text="close_buzzer";
        emit close_open_Signal(text);
    }
}

void ModbusWig::on_led1_Button_clicked()         //led1
{
    QIcon icon1;
    if(led1_i==0)//关
    {

        icon1.addFile(":/images/open_led.png");
        ui->led1_Button->setMinimumSize(100,150);
        ui->led1_Button->setMaximumSize(300,150);
        ui->led1_Button->setIcon(icon1);
        ui->led1_Button->setIconSize(QSize(50,50));
        led1_i=1;
        QString text="open_led1";
        emit close_open_Signal(text);
    }
    else
    {
        icon1.addFile(":/images/close_led.png");
        ui->led1_Button->setMinimumSize(100,150);
        ui->led1_Button->setMaximumSize(300,150);
        ui->led1_Button->setIcon(icon1);
        ui->led1_Button->setIconSize(QSize(50,50));
        led1_i=0;
        QString text="close_led1";
        emit close_open_Signal(text);
    }
}

void ModbusWig::on_led2_Button_clicked()        //led2
{
    QIcon icon1;
    if(led2_i==0)//关
    {

        icon1.addFile(":/images/open_led.png");
        ui->led2_Button->setMinimumSize(100,150);
        ui->led2_Button->setMaximumSize(300,150);
        ui->led2_Button->setIcon(icon1);
        ui->led2_Button->setIconSize(QSize(50,50));
        led2_i=1;
        QString text="open_led2";
        emit close_open_Signal(text);
    }
    else
    {
        icon1.addFile(":/images/close_led.png");
        ui->led2_Button->setMinimumSize(100,150);
        ui->led2_Button->setMaximumSize(300,150);
        ui->led2_Button->setIcon(icon1);
        ui->led2_Button->setIconSize(QSize(50,50));
        led2_i=0;
        QString text="close_led2";
        emit close_open_Signal(text);
    }
}

void ModbusWig::on_led3_Button_clicked()         // led3
{
    QIcon icon1;
    if(led3_i==0) // 关
    {
        icon1.addFile(":/images/open_led.png");
        ui->led3_Button->setMinimumSize(100,150);
        ui->led3_Button->setMaximumSize(300,150);
        ui->led3_Button->setIcon(icon1);
        ui->led3_Button->setIconSize(QSize(50,50));
        led3_i=1;
        QString text="open_led3";
        emit close_open_Signal(text);
    }
    else
    {
        icon1.addFile(":/images/close_led.png");
        ui->led3_Button->setMinimumSize(100,150);
        ui->led3_Button->setMaximumSize(300,150);
        ui->led3_Button->setIcon(icon1);
        ui->led3_Button->setIconSize(QSize(50,50));
        led3_i=0;
        QString text="close_led3";
        emit close_open_Signal(text);
    }
}

void ModbusWig::on_led4_Button_clicked()        // led4
{
    QIcon icon1;
    if(led4_i==0) // 关
    {
        icon1.addFile(":/images/open_led.png");
        ui->led4_Button->setMinimumSize(100,150);
        ui->led4_Button->setMaximumSize(300,150);
        ui->led4_Button->setIcon(icon1);
        ui->led4_Button->setIconSize(QSize(50,50));
        led4_i=1;
        QString text="open_led4";
        emit close_open_Signal(text);
    }
    else
    {
        icon1.addFile(":/images/close_led.png");
        ui->led4_Button->setMinimumSize(100,150);
        ui->led4_Button->setMaximumSize(300,150);
        ui->led4_Button->setIcon(icon1);
        ui->led4_Button->setIconSize(QSize(50,50));
        led4_i=0;
        QString text="close_led4";
        emit close_open_Signal(text);
    }
}

